package com.jincheng.web;

import com.jincheng.pojo.Auction;
import com.jincheng.service.AuctionService;
import com.jincheng.utils.Constant;
import com.jincheng.utils.R;
import my.framework.anno.RequestMapping;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author Jane
 * @date 2024-12-16 10:40
 */

public class AuctionController {

    @RequestMapping("/auction/list")
    public R getAuctionList(HttpServletRequest request , HttpServletResponse response){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("auctionUserApplication.xml");
        //根据类名称去找对应的java类
//            AuctionuserService auctionuserService = (AuctionuserService) ctx.getBean("auctionuserServiceImpl");// new AuctionuserServiceImpl();
        //根据自定义的名称去找对应的java类
        AuctionService auctionService = (AuctionService) ctx.getBean("auctionService");// new AuctionuserServiceImpl();

        Auction paramsAuction=new Auction();

        paramsAuction.setAuctionname(request.getParameter("auctionName") ==null?"":request.getParameter("auctionName"));
        paramsAuction.setAuctionstartprice(Double.valueOf(request.getParameter("auctionStartPrice")==null?"-1":request.getParameter("auctionStartPrice")));//new BigDecimal(1800)

        paramsAuction.setAuctionstarttime(request.getParameter("auctionstarttime"));
        paramsAuction.setAuctionendtime(request.getParameter("auctionendtime"));

        int currPage = request.getParameter("currPage")==null ? 1:
                Integer.parseInt(request.getParameter("currPage"));

        int pageSize = request.getParameter("pageSize")==null ?  Constant.PAGE_SIZE:
                Integer.parseInt(request.getParameter("pageSize"));
        List<Auction> acutionList =    auctionService.findAcutionList(paramsAuction,currPage ,pageSize);

        return R.ok(acutionList);
    }

}
